package org.example.user.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.example.user.domain.Role;
import org.example.user.service.RoleMenuService;
import org.example.user.service.RoleService;
import org.example.user.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("role")
public class RoleController {
    @Autowired
    private RoleService roleService;
    @Autowired
    private RoleMenuService roleMenuService;
//    岗位列表查询
    @RequestMapping("list")
    public Result    list(@RequestBody Role role, Integer current, Integer size) {
        PageHelper.startPage(current,size);
        List<Role> list = roleService.listAll(role);
        return Result.success(new PageInfo<>(list));

    }
    @RequestMapping("list2")
    public Result list2(){
        List<Role> list = roleService.list();
        return Result.success(list);
    }
    @RequestMapping("getRoleByUserId")
    public Result userId(Integer userId) {
        Role byId = roleService.getByUserId(userId);
        return Result.success(byId.getId());
    }
    @RequestMapping("updateRoleMenu")
    public Result updateRoleMenu(@RequestBody Role role){
        boolean b = roleService.updateRoleMenu(role);
        return b?Result.success():Result.fail();
    }
    @RequestMapping("getMenuIdByRoleId")
    public Result getMenuIdByRoleId(Integer id){
        List<Integer> list = roleMenuService.getMenuIdByRoleId(id);
        return Result.success(list);
    }

}
